package com.dingding.user.core.passenger.coupon.dao.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.common.core.base.daox.AbstractBaseInjectionDao;
import com.dingding.common.core.beans.UserCoupon;
import com.dingding.user.core.passenger.coupon.dao.IUserCouponDao;

/**
 * 
 * @Description: 用户优惠券DAO
 * @author CHEHUANBO
 * @date 2016年12月13日
 * @version V2.6.2
 * 
 */
@Component("_userCouponDao")
public class UserCouponDaoImpl extends AbstractBaseInjectionDao implements IUserCouponDao {

	/**
	 * 
	 * @Description: 通过用户ID获取用户有效优惠券
	 * @param userId
	 *            用户ID
	 * @author CHEHUANBO
	 * @version V2.6.2
	 * 
	 */
	@Override
	@Transactional(readOnly = true)
	public List<UserCoupon> getUserCoupon(String userId) throws RuntimeException {

		if (StringUtils.isBlank(userId)) {
			throw new NullPointerException("通过用户ID获取用户有效优惠券被拒绝！原因：userId is null");
		}

		Criterion criterion = Restrictions.and(Restrictions.eq("loginId", userId), Restrictions.eq("couponStatus", 2));

		List<UserCoupon> userCouponList = super.getCriteriaBaseDao().queryCriteriaList(UserCoupon.class, criterion);

		return userCouponList;

	}

	/**
	 * 
	 * @Description: 添加用户优惠券
	 * @param userCoupon
	 * @author CHEHUANBO
	 * @version V2.6.2
	 * 
	 */
	@Override
	public void addUserCoupon(UserCoupon userCoupon) throws RuntimeException {
		super.getBaseDaoX().save(userCoupon);
	}
	
	
	/**
	 * 
	 * @Description: 锁定优惠券
	 * @throws RuntimeException
	 * @author CHEHUANBO
	 * @version V2.6.2
	 * 
	 */
	@Transactional(isolation = Isolation.READ_COMMITTED)
	public void lockUserCoupon(String couponId){
		
		
		
	}

}
